import Vue from "vue"
import Router from 'vue-router'
import Cart from '@/views/Cart.vue'
import Chart from '@/views/Chart.vue'
import My from '@/views/My.vue'
import Look from '@/views/Look.vue'
import SearchListshow from "@/views/SearchListshow"
import login from "../views/Login"
import Index from '@/views/Index.vue'
import chatList from  '@/components/ChatList.vue'
import GoodsDeatil from "@/components/GoodsDeatil";
import PublishGoods from "@/views/PublishGoods";
import SubmitOrder from "@/views/SubmitOrder";
import ToPay from "@/views/ToPay";
import Edit from "@/views/Edit";
import ReUseGoods from "@/views/ReUseGoods";
import WantBuy from "@/views/WantBuy";
import SelectAddress from "@/views/SelectAddress";
import Address from "@/views/Address";
import WantBuySend from "@/views/WantBuySend"
import OrderLists from "@/views/OrderLists"
import Give from "@/views/Give";
Vue.use(Router)

const router=new Router({
  routes:[
    {
      path:'/',
      name:'Index',
      component:Index,
      meta:{
        keepAlive:true//导航栏在该页面显示
      }
    },
    {
      path:'/SearchListshow',
      name:'SearchList',
      component:SearchListshow,
      meta:{
        keepAlive:false//导航栏在该页面显示
      }
    },
    {
      path:'/Give',
      name:'Give',
      component:Give,
      meta:{
        keepAlive:false//导航栏在该页面显示
      }
    },
    {
      path:'/OrderLists',
      name:'OrderLists',
      component:OrderLists,
      meta:{
        keepAlive:false//导航栏在该页面显示
      }
    },
    {
      path:'/WantBuySend',
      name:'WantBuySend',
      component:WantBuySend,
      meta:{
        keepAlive:false//导航栏在该页面显示
      }
    },
    {
      path:'/AddressPage',
      name:'AddressPage',
      component:Address,
      meta:{
        keepAlive:false//导航栏在该页面显示
      }
    },
    {
      path:'/selectAddress',
      name:'selectAddress',
      component:SelectAddress,
      meta:{
        keepAlive:false//导航栏在该页面显示
      }
    },
    {
      path:'/publishGoods',
      name:'PublishGoods',
      component:PublishGoods,
      meta:{
        keepAlive:false//导航栏在该页面显示
      }
    },
    {
      path:'/Edit',
      name:'Edit',
      component:Edit,
      meta:{
        keepAlive:false//导航栏在该页面显示
      }
    },
    {
      path:'/ReUse',
      name:'ReUse',
      component:ReUseGoods,
      meta:{
        keepAlive:false//导航栏在该页面显示
      }
    },
    {
      path:'/login',
      name:'login',
      component:login,
      meta:{
        keepAlive:false//导航栏在该页面显示
      }
    },
    {
      path:'/WantBuy',
      name:'WantBuy',
      component:WantBuy,
      meta:{
        keepAlive:false//导航栏在该页面显示
      }
    },
    {
      path:'/SubmitOrder',
      name:'SubmitOrder',
      component:SubmitOrder,
      meta:{
        keepAlive:false//导航栏在该页面显示
      }
    },
    {
      path:'/Cart',
      name:'Cart',
      component:Cart,
      meta:{
        keepAlive:true//导航栏在该页面显示
      }
    },
    {
      path:'/ToPay',
      name:'ToPay',
      component:ToPay,
      meta:{
        keepAlive:true//导航栏在该页面显示
      }
    },
    {
      path:'/GoodsDetail/:id',
      name:'GoodsDeatil',
      component:GoodsDeatil,
      meta:{
        keepAlive:false//导航栏在该页面显示
      }
    },
    {
      path:'/Chart',
      name:'Chart',
      component:Chart,
      meta:{
        keepAlive:true//导航栏在该页面显示
      },
      children:[

      ]
    },
    {
      path:'/Chart/chatList/:id',
      name:'chatList',
      component:chatList,
      meta:{
        keepAlive:false//导航栏在该页面显示
      }
    },
    {
      path:'/My',
      name:'My',
      component:My,
      meta:{
        keepAlive:true//导航栏在该页面显示
      },
      children:[
        {
          path:'send',
          name:'send',
          component:Index
        }
      ]
    },
    {
      path:'/Look',
      name:'Look',
      component:Look,
      meta:{
        keepAlive:true//导航栏在该页面显示
      }
    }
  ]
})

router.beforeEach((to, from, next) => {
 if (to.path === '/login') return next()
  // 获取token
  // localStorage.setItem('token',"678")
  let tokenStr = localStorage.getItem("token")
  if (!tokenStr ) return next('/login')
  next()
})
export default router
